package ru.mirent;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import ru.mirent.SvgTypeDiagram;

import java.io.File;

public class SvgTypeDiagramTest {

    @Test
    void positiveGenerateCodeDiagramTest() {
        String source = "@startuml\n" +
                "Bob -> Alice : hello\n" +
                "@enduml";

        SvgTypeDiagram svgTypeDiagram = new SvgTypeDiagram(source);

        String actual = svgTypeDiagram.svgCode();
        String expected = "<?xml version=\"1.0\" encoding=\"us-ascii\" standalone=\"no\"?><svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" contentStyleType=\"text/css\" height=\"124px\" preserveAspectRatio=\"none\" style=\"width:104px;height:124px;background:#FFFFFF;\" version=\"1.1\" viewBox=\"0 0 104 124\" width=\"104px\" zoomAndPan=\"magnify\"><defs/><g><line style=\"stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;\" x1=\"24\" x2=\"24\" y1=\"37.6094\" y2=\"87.9609\"/><line style=\"stroke:#181818;stroke-width:0.5;stroke-dasharray:5.0,5.0;\" x1=\"76\" x2=\"76\" y1=\"37.6094\" y2=\"87.9609\"/><rect fill=\"#E2E2F0\" height=\"31.6094\" rx=\"2.5\" ry=\"2.5\" style=\"stroke:#181818;stroke-width:0.5;\" width=\"39\" x=\"5\" y=\"5\"/><text fill=\"#000000\" font-family=\"sans-serif\" font-size=\"14\" lengthAdjust=\"spacing\" textLength=\"25\" x=\"12\" y=\"26.5332\">Bob</text><rect fill=\"#E2E2F0\" height=\"31.6094\" rx=\"2.5\" ry=\"2.5\" style=\"stroke:#181818;stroke-width:0.5;\" width=\"39\" x=\"5\" y=\"86.9609\"/><text fill=\"#000000\" font-family=\"sans-serif\" font-size=\"14\" lengthAdjust=\"spacing\" textLength=\"25\" x=\"12\" y=\"108.4941\">Bob</text><rect fill=\"#E2E2F0\" height=\"31.6094\" rx=\"2.5\" ry=\"2.5\" style=\"stroke:#181818;stroke-width:0.5;\" width=\"44\" x=\"54\" y=\"5\"/><text fill=\"#000000\" font-family=\"sans-serif\" font-size=\"14\" lengthAdjust=\"spacing\" textLength=\"30\" x=\"61\" y=\"26.5332\">Alice</text><rect fill=\"#E2E2F0\" height=\"31.6094\" rx=\"2.5\" ry=\"2.5\" style=\"stroke:#181818;stroke-width:0.5;\" width=\"44\" x=\"54\" y=\"86.9609\"/><text fill=\"#000000\" font-family=\"sans-serif\" font-size=\"14\" lengthAdjust=\"spacing\" textLength=\"30\" x=\"61\" y=\"108.4941\">Alice</text><polygon fill=\"#181818\" points=\"64,65.9609,74,69.9609,64,73.9609,68,69.9609\" style=\"stroke:#181818;stroke-width:1.0;\"/><line style=\"stroke:#181818;stroke-width:1.0;\" x1=\"24.5\" x2=\"70\" y1=\"69.9609\" y2=\"69.9609\"/><text fill=\"#000000\" font-family=\"sans-serif\" font-size=\"13\" lengthAdjust=\"spacing\" textLength=\"27\" x=\"31.5\" y=\"65.1045\">hello</text><!--SRC=[SyfFKj2rKt3CoKnELR1Io4ZDoSa70000]--></g></svg>";

        Assertions.assertEquals(expected, actual);
    }

    /**
     * Результат проверки теста - одноименный сохраненный файл.
     */
    @Disabled
    @Test
    void positiveSaveDiagramTest() {
        String source = "@startuml\n" +
                "Bob -> Alice : hello\n" +
                "@enduml";

        SvgTypeDiagram svgTypeDiagram = new SvgTypeDiagram(source);
        svgTypeDiagram.saveToFile(new File("test.svg"));
    }

    @Test
    void negativeGenerateCodeDiagramTest() {
        String source = "@startuml";

        SvgTypeDiagram svgTypeDiagram = new SvgTypeDiagram(source);

        RuntimeException failed = Assertions.assertThrows(RuntimeException.class,
                () -> svgTypeDiagram.svgCode()
        );
        Assertions.assertEquals("Ошибка генерации диаграммы", failed.getMessage());
    }
}
